//
//  CustomerServiceViewController.m
//  suRead
//
//  Created by colin on 2020/1/5.
//  Copyright © 2020 bao. All rights reserved.
//

#import "CustomerServiceViewController.h"
#import "Masonry.h"
#import "UIControl+Blocks.h"

@interface CustomerServiceViewController ()<UIWebViewDelegate>
@property (nonatomic,strong) UIWebView *infoWebView;
@end

@implementation CustomerServiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
         
    UIView *bottomBarView = [UIView new];
    [self.view addSubview:bottomBarView];
    [bottomBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
        if (iPhoneX) {
            make.height.equalTo(@88.0f);
        } else {
            make.height.equalTo(@64.0f);
        }
    }];
    
    __weak typeof(self) weakSelf = self;
    UIButton *buttonWebViewBack= [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonWebViewBack setImage:[UIImage imageNamed:@"btn_refresh"] forState:UIControlStateNormal];
    [bottomBarView addSubview:buttonWebViewBack];
    [buttonWebViewBack addActionForControlEvents:UIControlEventTouchUpInside usingBlock:^(UIControl *sender, UIEvent *event) {
        [weakSelf.infoWebView reload];
    }];
    [buttonWebViewBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(buttonWebViewBack.superview).with.offset(5.0);
        make.bottom.equalTo(buttonWebViewBack.superview);
        make.width.equalTo(@44.0f);
        make.height.equalTo(@44.0f);
    }];
    
    UILabel *labelTitle = [UILabel new];
    labelTitle.textColor = [UIColor blackColor];
    labelTitle.text = @"智能客服";
    labelTitle.font = [UIFont fontWithName:@"FZBIAOYSJW--GB1-0" size:17.0f];
    [bottomBarView addSubview:labelTitle];
    [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(labelTitle.superview);
        make.bottom.equalTo(labelTitle.superview);
        make.height.equalTo(@44.0f);
    }];
    
    UILabel *linelab = [UILabel new];
    linelab.backgroundColor = [UIColor colorWithRed:160/255.0f green:160/255.0f blue:160/255.0f alpha:1.0f];
    [bottomBarView addSubview:linelab];
    [linelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(bottomBarView);
        make.height.equalTo(@0.5f);
    }];
    
    self.infoWebView = [UIWebView new];
    self.infoWebView.scalesPageToFit = YES;
    self.infoWebView.scrollView.bounces = NO;
    self.infoWebView.delegate = self;
    [self.view addSubview:self.infoWebView];
    [self.infoWebView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(bottomBarView.mas_bottom);
        make.bottom.equalTo(self.view);
    }];
    
    NSString *source_url = @"http://im.cxipcc.cn/tccrm2_saas_im/im/visit/text/9713f8d65202eddc53d27196177649a2.html";
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:source_url]];
    [self.infoWebView loadRequest:request];
}

@end
